package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.AuxiliaryMeasures;
import com.css.fxfzaqbz.modules.data.queryParams.SeismicHazardAssessQueryParams;
import com.css.fxfzaqbz.modules.data.service.AuxiliaryMeasuresService;
import com.css.fxfzaqbz.modules.data.vo.BigStatusVo;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 辅助分析页面
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class AuxiliaryMeasuresController {

    @Resource
    AuxiliaryMeasuresService auxiliaryMeasuresService;
    /**
     * 查询
     * @param request
     * @param auxiliaryMeasures
     * @return
     */
    @GetMapping("/getAllAuxiliaryMeasures")
    public RestResponse getAllAuxiliaryMeasures(HttpServletRequest request, AuxiliaryMeasures auxiliaryMeasures) {

        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            auxiliaryMeasures.setCurPage(curPage);
            auxiliaryMeasures.setPageSize(pageSize*2);
            Map<String, Object> allSeismicHazardAssess = auxiliaryMeasuresService.getAllAuxiliaryMeasures(auxiliaryMeasures);
            if (allSeismicHazardAssess==null){
                restResponse = RestResponse.fail("完善个人地址信息后查看");
            }else {
                restResponse = RestResponse.succeed(allSeismicHazardAssess);
            }

        } catch (Exception e) {
            log.error("查询辅助分析数据失败", e);
            restResponse = RestResponse.fail("查询辅助分析数据失败");
        }
        return restResponse;
    }

    //进入的时候修改状态
    @PostMapping("/updateAuxiliaryStatus")
    public RestResponse updateBigStatus(String id) {
        RestResponse restResponse = null;
        try {
            auxiliaryMeasuresService.updateBigStatus(id);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("处理失败", e);
            restResponse = RestResponse.fail("处理失败!");
        }
        return restResponse;
    }
}
